using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using LeisureCenter.Tools;

namespace LeisureCenter.Forms
{
    public partial class ScreensaverForm : Form
    {
        private Point lastCursorPos;

        public ScreensaverForm()
        {
            InitializeComponent();
        }

        private void timerOpacity_Tick(object sender, EventArgs e)
        {
            if (Opacity < 0.8)
                Opacity += 0.05;
            else
                timerOpacity.Stop();
        }

        private void ScreensaverForm_Click(object sender, EventArgs e)
        {
            Hide();
        }

        private void ScreensaverForm_MouseMove(object sender, MouseEventArgs e)
        {
            Point newCursorPos = Cursor.Position;
            if (lastCursorPos != newCursorPos)
            {
                lastCursorPos = newCursorPos;
                Hide();
            }
        }

        public new void Show()
        {
            if (!Debugger.IsAttached)
            {
                Opacity = 0;
                lastCursorPos = Cursor.Position;
                Control previewWindow = Program.LeisureCenterInstance.MainForm.GetActivePreviewWindow();
                pnlPreview.Visible = previewWindow != null;
                pnlPreview.Bounds = Utils.GetControlScreenBounds(previewWindow);
                timerOpacity.Start();
                BringToFront();
                base.Show();
            }
        }
    }
}